/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ar.edu.utn.frsf.cidisi.ginet.formalization.impl;

import ar.edu.utn.frsf.cidisi.ginet.abstractginet.AbstractginetPackage;
import ar.edu.utn.frsf.cidisi.ginet.GinetPackage;

import ar.edu.utn.frsf.cidisi.ginet.formalization.FormalAssociation;
import ar.edu.utn.frsf.cidisi.ginet.formalization.FormalCBPLanguage;
import ar.edu.utn.frsf.cidisi.ginet.formalization.FormalElement;
import ar.edu.utn.frsf.cidisi.ginet.formalization.FormalizationFactory;
import ar.edu.utn.frsf.cidisi.ginet.formalization.FormalizationPackage;
import java.io.IOException;
import java.net.URL;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import ar.edu.utn.frsf.cidisi.ginet.formalization.MetamodelElement;
import ar.edu.utn.frsf.cidisi.ginet.formalization.RootElement;

import java.util.Map;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EReference;

import org.eclipse.emf.ecore.impl.EPackageImpl;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.emf.ecore.xml.type.XMLTypePackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model <b>Package</b>.
 * <!-- end-user-doc -->
 * @generated
 */
public class FormalizationPackageImpl extends EPackageImpl implements FormalizationPackage {
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected String packageFilename = "formalization.ecore";

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	private EClass formalCBPLanguageEClass = null;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	private EClass formalAssociationEClass = null;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	private EClass formalElementEClass = null;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	private EClass metamodelElementEClass = null;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	private EClass rootElementEClass = null;

	/**
	 * Creates an instance of the model <b>Package</b>, registered with
	 * {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package
	 * package URI value.
	 * <p>Note: the correct way to create the package is via the static
	 * factory method {@link #init init()}, which also performs
	 * initialization of the package, or returns the registered package,
	 * if one already exists.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see org.eclipse.emf.ecore.EPackage.Registry
	 * @see ar.edu.utn.frsf.cidisi.ginet.formalization.FormalizationPackage#eNS_URI
	 * @see #init()
	 * @generated
	 */
	private FormalizationPackageImpl() {
		super(eNS_URI, FormalizationFactory.eINSTANCE);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	private static boolean isInited = false;

	/**
	 * Creates, registers, and initializes the <b>Package</b> for this model, and for any others upon which it depends.
	 * 
	 * <p>This method is used to initialize {@link FormalizationPackage#eINSTANCE} when that field is accessed.
	 * Clients should not invoke it directly. Instead, they should simply access that field to obtain the package.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #eNS_URI
	 * @generated
	 */
	public static FormalizationPackage init() {
		if (isInited) return (FormalizationPackage)EPackage.Registry.INSTANCE.getEPackage(FormalizationPackage.eNS_URI);

		// Obtain or create and register package
		FormalizationPackageImpl theFormalizationPackage = (FormalizationPackageImpl)(EPackage.Registry.INSTANCE.get(eNS_URI) instanceof FormalizationPackageImpl ? EPackage.Registry.INSTANCE.get(eNS_URI) : new FormalizationPackageImpl());

		isInited = true;

		// Initialize simple dependencies
		AbstractginetPackage.eINSTANCE.eClass();
		XMLTypePackage.eINSTANCE.eClass();

		// Load packages
		theFormalizationPackage.loadPackage();

		// Fix loaded packages
		theFormalizationPackage.fixPackageContents();

		// Mark meta-data to indicate it can't be changed
		theFormalizationPackage.freeze();

  
		// Update the registry and return the package
		EPackage.Registry.INSTANCE.put(FormalizationPackage.eNS_URI, theFormalizationPackage);
		return theFormalizationPackage;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EClass getFormalCBPLanguage() {
		if (formalCBPLanguageEClass == null) {
			formalCBPLanguageEClass = (EClass)EPackage.Registry.INSTANCE.getEPackage(FormalizationPackage.eNS_URI).getEClassifiers().get(0);
		}
		return formalCBPLanguageEClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EReference getFormalCBPLanguage_FormalizedElements() {
        return (EReference)getFormalCBPLanguage().getEStructuralFeatures().get(0);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EAttribute getFormalCBPLanguage_CbpMetamodel() {
        return (EAttribute)getFormalCBPLanguage().getEStructuralFeatures().get(1);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EAttribute getFormalCBPLanguage_AbstractGINet() {
        return (EAttribute)getFormalCBPLanguage().getEStructuralFeatures().get(2);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EReference getFormalCBPLanguage_RootElement() {
        return (EReference)getFormalCBPLanguage().getEStructuralFeatures().get(3);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EClass getFormalAssociation() {
		if (formalAssociationEClass == null) {
			formalAssociationEClass = (EClass)EPackage.Registry.INSTANCE.getEPackage(FormalizationPackage.eNS_URI).getEClassifiers().get(1);
		}
		return formalAssociationEClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EAttribute getFormalAssociation_Value() {
        return (EAttribute)getFormalAssociation().getEStructuralFeatures().get(1);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EAttribute getFormalAssociation_Key() {
        return (EAttribute)getFormalAssociation().getEStructuralFeatures().get(0);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EClass getFormalElement() {
		if (formalElementEClass == null) {
			formalElementEClass = (EClass)EPackage.Registry.INSTANCE.getEPackage(FormalizationPackage.eNS_URI).getEClassifiers().get(2);
		}
		return formalElementEClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EReference getFormalElement_Element() {
        return (EReference)getFormalElement().getEStructuralFeatures().get(0);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EClass getMetamodelElement() {
		if (metamodelElementEClass == null) {
			metamodelElementEClass = (EClass)EPackage.Registry.INSTANCE.getEPackage(FormalizationPackage.eNS_URI).getEClassifiers().get(3);
		}
		return metamodelElementEClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EReference getMetamodelElement_Element() {
        return (EReference)getMetamodelElement().getEStructuralFeatures().get(0);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EClass getRootElement() {
		if (rootElementEClass == null) {
			rootElementEClass = (EClass)EPackage.Registry.INSTANCE.getEPackage(FormalizationPackage.eNS_URI).getEClassifiers().get(4);
		}
		return rootElementEClass;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EReference getRootElement_Element() {
        return (EReference)getRootElement().getEStructuralFeatures().get(0);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public FormalizationFactory getFormalizationFactory() {
		return (FormalizationFactory)getEFactoryInstance();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	private boolean isLoaded = false;

	/**
	 * Laods the package and any sub-packages from their serialized form.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void loadPackage() {
		if (isLoaded) return;
		isLoaded = true;

		URL url = getClass().getResource(packageFilename);
		if (url == null) {
			throw new RuntimeException("Missing serialized package: " + packageFilename);
		}
		URI uri = URI.createURI(url.toString());
		Resource resource = new EcoreResourceFactoryImpl().createResource(uri);
		try {
			resource.load(null);
		}
		catch (IOException exception) {
			throw new WrappedException(exception);
		}
		initializeFromLoadedEPackage(this, (EPackage)resource.getContents().get(0));
		createResource(eNS_URI);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	private boolean isFixed = false;

	/**
	 * Fixes up the loaded package, to make it appear as if it had been programmatically built.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void fixPackageContents() {
		if (isFixed) return;
		isFixed = true;
		fixEClassifiers();
	}

	/**
	 * Sets the instance class on the given classifier.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected void fixInstanceClass(EClassifier eClassifier) {
		if (eClassifier.getInstanceClassName() == null) {
			eClassifier.setInstanceClassName("ar.edu.utn.frsf.cidisi.ginet.formalization." + eClassifier.getName());
			setGeneratedClassName(eClassifier);
		}
	}

} //FormalizationPackageImpl
